#! /usr/bin/env python
#coding=utf-8

from get_month_quarter import *
from get_weekreport_detail import *

#from __future__ import division


#调用get_month_quarter.py中get_db_connection()获取数据库联接
db = get_db_connection()

#meta = MetaData(db)
#db.metadata.reflect()
    
def run():
    if len(sys.argv)>1:
        if sys.argv[1] == '2':
            first_day,last_day = get_last_week()
        else:
            first_day,last_day = get_week()
    else:
        first_day,last_day = get_week()
#    print  'first_day,last_day', first_day,last_day
#    first_day,last_day = get_week()
#    report_type = '1'
    data =  get_weekreport_detail(first_day,last_day)

                        


if __name__ == '__main__':
    try:
        db.begin()
        run()
        db.commit()
        log.info("finish")
    except Exception, e:
        db.rollback()
        log.exception(e)
        log.error('error')
        raise
